using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Windows.Forms;
using Microsoft.VisualStudio.DebuggerVisualizers;

[assembly: System.Diagnostics.DebuggerVisualizer(typeof(SPDV.SPListItemDebuggerVisualizer), typeof(SPDV.SPListItemObjectProvider),
   Target = typeof(Microsoft.SharePoint.SPListItem), Description = "SPListItem data")]
namespace SPDV
{
    // TODO: Add the following to SomeType's definition to see this visualizer when debugging instances of SomeType:
    // 
    //  Refactor to reuse part of the code from SPList
    /// <summary>
    /// A Visualizer for SomeType.  
    /// </summary>
    public class SPListItemDebuggerVisualizer : DialogDebuggerVisualizer
    {
        protected override void Show(IDialogVisualizerService windowService, IVisualizerObjectProvider objectProvider)
        {
            // TODO: Get the object to display a visualizer for.
            //       Cast the result of objectProvider.GetObject() 
            //       to the type of the object being visualized.
            SPListItemData data = (SPListItemData)objectProvider.GetObject();

            // TODO: Display your view of the object.
            //       Replace displayForm with your own custom Form or Control.
            using (SPListItemForm displayForm = new SPListItemForm())
            {
                displayForm.ListItemData = data;
                windowService.ShowDialog(displayForm);
            }
        }

        // TODO: Add the following to your testing code to test the visualizer:
        // 
        //    SPListItemDebuggerVisualizer.TestShowVisualizer(new SomeType());
        // 
        /// <summary>
        /// Tests the visualizer by hosting it outside of the debugger.
        /// </summary>
        /// <param name="objectToVisualize">The object to display in the visualizer.</param>
        public static void TestShowVisualizer(object objectToVisualize)
        {
            VisualizerDevelopmentHost visualizerHost = new VisualizerDevelopmentHost(objectToVisualize, typeof(SPListItemDebuggerVisualizer));
            visualizerHost.ShowVisualizer();
        }
    }
}